package com.yuanshen.util;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.FanoutExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author 28691
 * 配置类方式实现交换器与队列绑定
 */
@Configuration
public class FanoutConfig {
    @Bean
    public FanoutExchange fanoutExchange() {
        return new FanoutExchange("zhuhq.fanout");
    }

    @Bean
    @Qualifier("fanoutQueue1") // 使用@Qualifier指定bean的名称
    public Queue fanoutQueue1() {
        return new Queue("zhuhq.queue1");
    }

    @Bean
    @Qualifier("fanoutQueue2") // 使用@Qualifier指定bean的名称
    public Queue fanoutQueue2() {
        return new Queue("zhuhq.queue2");
    }

    @Bean
    public Binding bindingQueue1(FanoutExchange fanoutExchange, @Qualifier("fanoutQueue1") Queue fanoutQueue1) {
        return BindingBuilder.bind(fanoutQueue1).to(fanoutExchange);
    }

    @Bean
    public Binding bindingQueue2(FanoutExchange fanoutExchange, @Qualifier("fanoutQueue2") Queue fanoutQueue2) {
        return BindingBuilder.bind(fanoutQueue2).to(fanoutExchange);
    }
}
